package cn.cmft.jc.transform.parse.strategy;

import cn.cmft.jc.transform.parse.ChangeDetail;
import net.sf.jsqlparser.statement.alter.AlterExpression;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * 处理删除列
 */
public class DropColumnParser implements AlterExpressionParser {
    @Override
    public List<ChangeDetail> parse(AlterExpression alterExpression) {
        ArrayList<ChangeDetail> columns = new ArrayList<>();
        Optional<String> columnNameOp = Optional.ofNullable(alterExpression.getColumnName());
        if (columnNameOp.isPresent()){
            String dropColumnName = columnNameOp.get().replace("`", "");
            columns.add(new ChangeDetail(dropColumnName));
        }
        return columns;
    }
}
